#pragma once
#ifndef _CSTR_HPP__
#define _CSTR_HPP__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>

#include <wrdc.h>
#define __WRD__DEBUG 1
#include <wrdbg.h>

// typedef char string[256];
typedef unsigned char uchar;

typedef struct cstr_s{
    char *start;
    int  size;
} cstr_t;

#define cstr_stack(str_name, str_size) \
cstr_t str_name; char str_name##_stack[str_size];\
str_name.start = str_name##_stack; \
str_name.size = str_size;

// @def init = 0/nullptr
cstr_t cstr_init(const char* init, int str_size);

cstr_t cstr(const char* init);

void cstr_free(cstr_t str);

int cstr_len(cstr_t string);

void debug_cstr(cstr_t string);

// when the work success, dest.start is removed, and return a new cstr_t object.
cstr_t cstr_join(cstr_t dest, cstr_t str2);

#endif  // _CSTR_HPP__